package com.studay.entity;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.extra.mail.Mail;
import cn.hutool.extra.mail.MailAccount;
import cn.hutool.extra.mail.MailUtil;
import com.sun.mail.util.MailSSLSocketFactory;

import java.security.GeneralSecurityException;

public class TestMail {
    public static void main(String[] args) throws GeneralSecurityException {

//        MailAccount mailAccount = new MailAccount();
//        mailAccount.setAuth(true);
//        mailAccount.setSslEnable(true);
//
//        MailSSLSocketFactory sf = new MailSSLSocketFactory();
//        sf.setTrustAllHosts(true);
////        mailAccount.setCustomProperty("mail.smtp.ssl.socketFactory", sf);
//
//        String mail = Mail.create(mailAccount)
//                .setTos("xx@xx.com")
//                .setTitle("邮箱验证")
//                .setContent("您的验证码是：<h3>2333</h3>")
//                .setHtml(true)
//                .send();


        sendMail();
//
//        String text = MailUtil.send("18739575480@163.com", "title.test", "mail.send.test", false, null);
//        System.out.println(text);
    }

    public static void sendMail(){
        MailAccount account = new MailAccount();
        account.setHost("smtp.139.com");
        account.setPort(25);
        account.setAuth(true);
        account.setFrom("18739575480@139.com");
        account.setUser("18739575480@139.com");
        account.setPass("8a2c52246fd84566c500");
        String send = MailUtil.send(account,
                CollUtil.newArrayList("18739575480@163.com"),
                "测试",
                "邮件来自Hutool测试",
                false);
        System.out.println("ok" + send);
    }
}
